(function() {
    var Yz = window.Yz = function() {};

    if (typeof console != "undefined") {
        console.log("Yz init");
    } else {
        window.console = { log: function() {} };
    }

    Yz.webPrefix = "/";

    Yz.loadedClasses = {};

    Yz.block = function()
    {
        console.log("block");
        document.body.style.cursor = "wait";
    }

    Yz.unblock = function()
    {
        console.log("unblock");
        document.body.style.cursor = "";
    }

    Yz.loadClass = function(className, callback)
    {
        var loadedClass;
        if (className in Yz.loadedClasses) {
            loadedClass = Yz.loadedClasses[className];
            callback(loadedClass);
        } else {
            Yz.block();
            try {
                var plugin = document.createElement("SCRIPT");
                plugin.src = Yz.webPrefix + "www/js/" + className + ".js";
                plugin.onload = function()
                {
                    console.log("Loaded class: "+className);
                    loadedClass = Yz.loadedClasses[className];
                    Yz.unblock();
                    callback(loadedClass);
                }
                document.getElementsByTagName("HEAD")[0].appendChild(plugin);
            } catch (ex) {
                Yz.Alert("Failed to load plugin " + plugin + ": " + ex);
                return false;
            }
        }
        return loadedClass;
    }

    /** %%% template for all Yz classes %%%
     *  the Yz.Upload class constructor
     *  syntax: var x = new Yz.Upload()
     *  Arguments: Object
     *  @param string formName
     *  @param string inputName
     *  @return new Yz.Upload
    Yz.Upload = function(args)
    {
        Yz.loadClass("Yz.Upload");
        var x = this;
        //alert(this);
        return this
            .init(args)
            .showDialog()
            ;
    }
     */

    Yz.translate =  function(message)
    {
        return message;
    }

    /**
     *  alert user with a message using a modal dialog
     *
     */
    Yz.Alert = function(message, title)
    {
        var dlg = Yz.Alert.dialog;
        if (! dlg) {
            dlg = document.createElement("DIV");
            dlg.className = "yz-dialog";
            var buttons = {};
            buttons["Cancel"] = function() { $(this).dialog("close"); }
            Yz.Alert.dialog = dlg;
            Yz.Alert.buttons = buttons;
        }
        if (! title) {
            title = Yz.translate("Alert");
        }
        $(dlg)
            .text(message)
            .dialog({
                modal: true,
                title: title,
                buttons: Yz.Alert.buttons
            });
        return Yz;
    }
    /**
     *  notify user with a message using a non-blocking UI element
     *
     */
    Yz.Notify = function(message)
    {
        alert(message);
        return Yz;
    }
})();
